package vn.wallet.app.task;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import vn.wallet.app.managedBean.SiteConfigBean;

public class ScheduledTask {

	private final static Logger logger = LoggerFactory.getLogger(ScheduledTask.class);
	private BackgroundTask configuredTask;
	private boolean active;

	@Resource
	private SiteConfigBean siteConfig;

	public synchronized void start() {
		if (configuredTask != null) {
			if (!isActive()) {
				logger.info("Cannot run {} task since is not activated", configuredTask.getName());
				return;
			}

			siteConfig.addNewTask(configuredTask);
			logger.debug("task {} added to queue", configuredTask.getName());
		}
	}

	public BackgroundTask getConfiguredTask() {
		return configuredTask;
	}

	public void setConfiguredTask(BackgroundTask configuredTask) {
		this.configuredTask = configuredTask;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

}
